public class Node(){
    public int value;
    public Node next;
    public Node(int data){
        this.value=data;
    }
}
public Node addTwoNumbers(Node head1,Node head2){
    Node dummy=new Node(-1);//head 
    int carry=0;
    Node pre=dummy;
    for(node pa=head1,pb=head2;
    pa!=null||pb!=null;
    pa=pa==null?null:pa.next,
    pb=pb==null?null:pb.next,
    pre=pre.next;){
       final int ai=pa==null?0:pa.value;
       final int bi=pb==null?0:pb.value;
       final int val=(ai+bi+carry)%10;
       carry=(ai+bi+carry)/10;
       pre.next=new Node(val);
    }
    if(carry>0){
        pre.next=new Node(carry);
    }
    return dummy.next;
}